<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区域 -->
    <el-card class="box-card">
      <!-- 搜索区 -->
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="query.query"
            class="input-with-select"
            :clearable="true"
            @clear="getOrderList()"
          >
            <el-button slot="append" icon="el-icon-search" @click="getOrderList()"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区 -->
      <el-table :data="orderList" stripe style="width: 100%" border>
        <el-table-column type="index" label="#" width="60"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="180">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status==0">未付款</el-tag>
            <el-tag type="success" v-else="scope.row.pay_status==0">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="180"></el-table-column>
        <el-table-column label="下单时间" width="180">
          <template slot-scope="scope">{{scope.row.create_time|dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scoped">
            <el-tooltip content="修改订单地址" placement="top" :enterable="false">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="editOrder(scoped.row)"
              ></el-button>
            </el-tooltip>
            <el-tooltip content="物流信息" placement="top" :enterable="false">
              <el-button
                type="success"
                icon="el-icon-position"
                size="mini"
                @click="sendInfo(scoped.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页栏 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改订单地址对话框 -->
    <el-dialog title="修改订单地址" :visible.sync="dialogVisible_editOrder" width="50%" @close="closed">
      <!-- 主体内容 -->
      <el-form
        :model="editOrderForm"
        :rules="editOrderFormRules"
        ref="editOrderFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县">
          <el-cascader
            v-model="editOrderForm.adress1"
            :options="data1"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="adress2">
          <el-input v-model="editOrderForm.adress2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible_editOrder = false">取 消</el-button>
        <el-button type="primary" @click="sureEditOrder">确 定</el-button>
      </span>
    </el-dialog>

    <!-- //物流信息对话框 -->
    <el-dialog title="物流进度" :visible.sync="dialogVisible" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in arr"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>
<script>
import data1 from "./city-data-element";
export default {
  data() {
    return {
      data1,
      //定义查询对象
      query: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      //订单数据
      orderList: [],
      //总数
      total: 0,
      //修改地址对话框
      dialogVisible_editOrder: false,
      //修改订单地址表单对象
      editOrderForm: {
        //级联选择选中的
        adress1: [],
        adress2: "",
      },
      //级联选择的配置
      setting: {
        expandTrigger: "hover",
        value: "value",
        label: "label",
        children: "children",
      },
      //修改订单表单验证规则
      editOrderFormRules: {
        adress2: [{ required: true, message: "请选择地址", trigger: "blur" }],
        adress1: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      //物流进度
      dialogVisible: false,
      //物流数据
      arr: [],
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    //获取表格数据
    async getOrderList() {
      const { data: res } = await this.axios.get("orders", {
        params: this.query,
      });
      if (res.meta.status !== 200) {
        return layer.msg(res.meta.msg, { time: 1000 });
      }
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    // 分页栏页面大小发生改变
    handleSizeChange(newPageSize) {
      this.query.pagesize = newPageSize;
      this.getOrderList();
    },
    //页码发生改变
    handleCurrentChange(newPageNum) {
      this.query.pagenum = newPageNum;
      this.getOrderList();
    },
    //修改订单地址
    editOrder(info) {
      this.dialogVisible_editOrder = true;
    },
    //确定修改订单地址按钮
    sureEditOrder() {},
    //物流信息按钮
    async sendInfo(info) {
      this.dialogVisible = true;
      const { data: res } = await this.axios.get("/kuaidi/1106975712662");
      if (res.meta.status != 200) {
        return layer.msg(res.meta.msg, { time: 1000 });
      }
      this.arr = res.data;
    },
    handleChange() {},
    closed() {
      this.$refs.editOrderFormRef.resetFields();
    },
  },
};
</script>

<style scoped>
@import "../../plugins/timeline/timeline.css";
@import "../../plugins/timeline-item/timeline-item.css";
.el-tag {
  margin: 0;
}
</style>